/*
 *
 *  projector
 *
 *  Created by Ilya Spivakov on 10/29/05.
 *  Copyright 2005 __MyCompanyName__. All rights reserved.
 *
 */

#include "settings.h"
#include <QFontDialog>
#include <QFileDialog>
#include <QTextStream>

SettingsWidget::SettingsWidget(QWidget *parent)
        : QWidget(parent)
{
    main_grid=new QGridLayout(this);
    font_button=new QPushButton("Change Font");
    wallpaper_button=new QPushButton("Change Wallpaper");
    main_grid->addWidget(font_button,0,0);
    main_grid->addWidget(wallpaper_button,1,0);
    connect(font_button,SIGNAL(clicked()),this,SLOT(ChangeFont()));
    connect(wallpaper_button,SIGNAL(clicked()),this,SLOT(ChangeWallpaper()));
/*   
    QFile cfgFile("font.cfg");
    cfgFile.open(QIODevice::Text | QIODevice::ReadOnly);
    font.fromString(cfgFile.readLine());
    emit FontChanged(font);
    cfgFile.close();
*/
	    
    
    
    //wallpaper_button->hide();




}

void SettingsWidget::ChangeFont()
{

    bool ok;
    QFont afont = QFontDialog::getFont(&ok,font, this);
    if (ok) {
        font=afont;
        emit FontChanged(font);
        QFile cfgFile("font.cfg");
        cfgFile.open(QIODevice::Truncate | QIODevice::Text | QIODevice::WriteOnly);
        QTextStream out(&cfgFile);
        out << font.toString();
        out.flush();
        cfgFile.close();



    } else {
        // the user canceled the dialog; font is set to the default
        // application font, QApplication::font()
    }

}


void SettingsWidget::ChangeWallpaper()
{
    QString s = QFileDialog::getOpenFileName(
                    this,
                    "Choose a file",
                    "/",
                    "Images (*.png *.xpm *.jpg)");
    QFile cfgFile("wallpaper.cfg");
    cfgFile.open(QIODevice::Truncate | QIODevice::Text | QIODevice::WriteOnly);
    QTextStream out(&cfgFile);
    out << s;
    out.flush();
    cfgFile.close();
    emit WallpaperChanged(s);
}


